Previous | Index | Next |

Function objects

Function objects are objects with an method perform() defined. They are important for the effective use of the library. In the places where one would expect to pass a pointer to a function to a generic algorithm, the interface is specified to accept an object with an operator() defined. For example, if we want to have a by-element addition of two vectors a and b containing Double and put the result into a we can do:
    transform(a.begin(), a.end(), b.begin(), a.begin(), new FuncSumDouble());
If we want to negate every element of a we can do:
    transform(a.begin(), a.end(), a.begin(), new FuncNegateDouble());
To enable adaptors and other components to manipulate function objects that take zero, one or two arguments interfaces is defined
    Function0 api
    Function1 api
    Function2 api

Aritmetic operations

The library provides basic function object classes for all of the arithmetic operators in the language. When an arithmic function object is created, the data type that should be operated on must be specified.
The function objects include
    FuncSum<type>
    FuncDifference<type>
    FuncDivides<type>
    FuncMultiply<type>
    FuncNegate<type>
    FuncModulus<type>
for each type
    Integer
    Long
    Float
    Double

Input-Output operations

The library provides basic function object classes for reading and writing objects from and to streams. The reading classes implements Function1 where the single argument is the DataInputStream to read from, and the new object just created is returned. The writing classes implements Function2 where the first argument is a DataOutputStream that must be written to and the second argument is the object that must be written. The return value is then ignored.
The function objects include:
    FuncWriter<type>
    FuncReader<type>
for each type
    Byte
    Short
    Integer
    Long
    Float
    Double
    Char
    String
    Boolean
For text output a FuncTextWriter api function object is created. This object will write the elements to the DataOutputStream with their text representaion. The text representation is created by calling the toString() method of the object.


Previous | Index | Next |